﻿using BuildStatus.Web.Models;
using Microsoft.TeamFoundation.Build.Client;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BuildStatus.Web.BuildServer
{
    public class BuildComparer : IComparer<BuildDefinition>
    {
        private const string InProgress = "InProgress"; // Microsoft.TeamFoundation.Build.Client.BuildStatus.InProgress

        public int Compare(BuildDefinition x, BuildDefinition y)
        {
            if (x.Status == InProgress)
            {
                if (x.Status != y.Status)
                    return -1;
            }
            if (y.Status == InProgress)
            {
                if (x.Status != y.Status)
                    return 1;
            }

            if (x.IsWaiting)
            {
                if (x.IsWaiting != y.IsWaiting)
                    return -1;
            }
            if (y.IsWaiting)
            {
                if (x.IsWaiting != y.IsWaiting)
                    return 1;
            }

            return -x.StartTime.CompareTo(y.StartTime);
        }
    }
}